package org.springcloud.wisdom.springcloud_03_freshman.admin.dao;

import org.apache.ibatis.annotations.*;
import org.springcloud.wisdom.springcloud_03_freshman.index.login.entity.Teacher;

import java.util.List;

@Mapper
public interface AdminTeacherDao {
    /**
     * 以分页的形式查看
     * @param start 页码数
     * @param size  每页记录数
     * @param tname 教师姓名
     * @param dept  教师所负责的院系
     * @param tid  教师的职工号
     * @return
     */
    @Select("<script>" +
            "SELECT * FROM teacher" +
            "  <where>" +
            "    <if test=\"tname != null\">" +
            "      tname = #{tname}" +
            "    </if>" +
            "    <if test=\"dept != null\">" +
            "     dept = #{dept} " +
            "    </if>" +
            "    <if test=\"tid != null\">" +
            "     tid = #{tid} " +
            "    </if>" +
            "</where>"+
            "limit #{start},#{size}"+
            "</script>")
    public List<Teacher> getTeacherByCond(int start, int size, String tname, Integer dept, String tid);

    @Select("<script>" +
            "SELECT count(*) FROM teacher" +
            "  <where>" +
            "    <if test=\"tname != null\">" +
            "      tname = #{tname}" +
            "    </if>" +
            "    <if test=\"dept != null\">" +
            "     dept = #{dept} " +
            "    </if>" +
            "    <if test=\"tid != null\">" +
            "     tid = #{tid} " +
            "    </if>" +
            "</where>"+
            "</script>")
    public int countTeacher(String tname,Integer dept,String tid);

    /**
     * 添加老师
     * @param teacher 教师实体类
     * @return
     */
    @Insert("insert into teacher(tid,tname,tpass,dept) values (#{tid},#{tname},#{tpass},#{dept})")
    public int addTeacher(Teacher teacher);

    /**
     * 根据职工号删除老师 逻辑上的删除
     * @param tid
     * @return
     */
    @Delete("delete from teacher where tid=#{tid}")
    public int deleteTeacher(String tid);

    /**
     * 可以修改老师的密码、所负责的院系
     * @param teacher
     * @return
     */
    @Update("<script>" +
            "  update teacher" +
            "        <set>" +
            "            <if test=\"null!= tpass\">" +
            "                tpass =#{tpass}," +
            "            </if>" +
            "            <if test=\"null!= dept\">" +
            "                dept =#{dept}," +
            "            </if>" +
            "        </set>" +
            "        where tid =#{tid}" +
            "</script>")
    public int updateTeacher(Teacher teacher);
}
